<?php

abstract class planostiposDAOImpl {

    public static function Select_Tipos($id_plan, $id_type) {
        if (DB::$mysqli = DB::Connection()) {
            $query = "select pt.id_plan, pt.id_type, t.name
                from plans_types pt inner join types t on t.id=pt.id_type";
            if (isset($id_plan)) {
                $query = $query . " where id_plan=? and id_type=?";
            }
            DB::$_stmt = DB::$mysqli->prepare($query);
            if (isset($id_plan)) {
                DB::$_stmt->bind_param('ii', $id_plan, $id_type);
            }
            if (!DB::$_stmt->execute()) {
                DB::$mysqli->error;
            }
            DB::$_stmt->bind_result($data_id_plan, $data_id_type, $data_name);
            while (DB::$_stmt->fetch()) {
                $data[] = array('id_plan' => $data_id_plan, 'id_type' => $data_id_type, 'name' => $data_name);
            }
            return $data;
        } else {
            error_log("erro ao conectar!");
        }
    }

    public static function Delete_Tipos($id) {
        if (DB::$mysqli = DB::Connection()) {
            $query = "delete from plans_types where id_plan = ?";
            DB::$_stmt = DB::$mysqli->prepare($query);
            DB::$_stmt->bind_param('i', $id);
            if (!DB::$_stmt->execute()) {
                echo DB::$mysqli->error;
            }
            return DB::$_stmt;
        } else {
            error_log("erro ao conectar!");
        }
    }

    public static function Insert($id_plan, $id_type) {
        if (DB::$mysqli = DB::Connection()) {
            $query = "insert into plans_types
                (id_plan,id_type) 
                values (?,?)";
            DB::$_stmt = DB::$mysqli->prepare($query);
            DB::$_stmt->bind_param('ii', $id_plan, $id_type);
            if (!DB::$_stmt->execute()) {
                echo DB::$mysqli->error;
            }
            return DB::$mysqli->insert_id;
        } else {
            error_log("erro ao conectar!");
        }
    }

}

?>
